Autogenerate spec_version and make it optional in netkans #4155
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
spec_version
in a .ckan file defines the earliest version of the CKAN client capable of loading a module and installing it correctly. Any modules with a spec version later than your CKAN client version will be hidden as if they did not exist, to avoid broken installs or crashing your client.Currently the spec version is required in a .netkan file and must be set to a safe version manually by the Metadata Wranglers. If a module uses a feature that is unavailable in its configured spec version, an inflation error is emitted and the module isn't indexed.
Motivation
Manually maintaining the spec version is tedious and error-prone. It is hard to know which features require specific versions or the versions they require, and it will only get more difficult as more versions with more features are released. Since this knowledge was added to the Netkan validators, we typically rely on inflation errors to alert us when there's a problem, which feels like unnecessarily inserting human action into a potentially fully automatable process. This is pretty off-putting for new Metadata Wranglers to have to deal with.
We can't even limit the impact of this to the CKAN team because author-maintained metanetkans and internal .ckan files also must obey the spec version rules. If the KSP-RO folks decide they want to use a brand new feature in one of their many metanetkans, either they would need to update the spec version on their own with no guardrails to let them know it's needed, or we would have to spot inflation errors from the bot and send them a pull request to update it.
Changes
SpecVersionTransformer
to analyze the inflated .ckan file and deduce the earliest compatible spec version that is safe to use, then sets it in the module. All of the existing spec version validation checks (which are still present as a safety measure) have been copied and modified to return the needed versions instead of throwing exceptions.CKAN.NetKAN.Model.Metadata
class no longer throws an exception in its constructor if the input JSON object has nospec_version
propertyThis makes
spec_version
optional in .netkan files (though still required in .ckan files); in effect, it has been changed from a human-maintained value to an autogenerated value. Merging these changes will cause the bot to update indexed modules to have the earliest compatible spec versions. It will also allow us to remove the now-optional-and-ignored spec version from existing netkans, the SpaceDock Adder, and the Metadata Webtool.Historical notes
To make sure that setting earlier spec versions will be safe for existing modules, I wanted to confirm that default install stanzas did not require a specific spec version. After some digging in the git log, it looks like they were added in #127, which was included in these releases:
All of which happened before version 1 of the spec, which corresponded to:
So it is confirmed safe to omit
install
in any spec version.